home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-31 | 2.2 KB | 124 lines | [TEXT/PJMM] |
- unit Operations;
-
- interface
-
- uses
- ParserGlobals;
-
- procedure realbinaryoperations (var realbinoperator: stringsize; var b1, b2, b3: extended; var error: str255);
-
- procedure realfunctionoperations (var realfunctiontype, realfctoperator: stringsize; var b1, b2, b3: extended; var error: str255);
-
- implementation
-
-
- procedure realbinaryoperations;
-
- label
- 999;
-
- var
- j, a, b, c: integer;
-
-
- begin
-
- {evaluating the real binary operations}
-
- if realbinoperator = plus then
- b3 := b1 + b2;
- if realbinoperator = minus then
- b3 := b1 - b2;
- if realbinoperator = asterisk then
- b3 := b1 * b2;
- if realbinoperator = equals then
- b3 := b2;
- if (realbinoperator = rightslash) and (b2 <> 0) then
- b3 := b1 / b2;
- if (realbinoperator = rightslash) and (b2 = 0) then
- begin
- error := 'divide by zero';
- goto 999;
- end;
- if realbinoperator = exponent then
- begin
- if b1 = 0 then
- b3 := 0;
- if b1 < 0 then
- b3 := -exp(b2 * ln(-b1));
- if b1 > 0 then
- b3 := exp(b2 * ln(b1));
- if b2 = 0 then
- b3 := 1;
- end;
- 999:
- end;
-
- procedure realfunctionoperations;
-
- label
- 999;
-
- var
- x1: extended;
- strvalue: string[30];
-
- begin
-
-
- if realfunctiontype = 'function' then
- begin
- if realfctoperator = 'sqrt' then
- begin
- if (b2 < 0) then
- begin
- error := 'taking the square root of a negative number';
- goto 999;
- end;
- if b2 >= 0 then
- b3 := sqrt(b2);
- end;
- if realfctoperator = 'sin' then
- b3 := sin(b2);
- if realfctoperator = 'cos' then
- b3 := cos(b2);
- if realfctoperator = 'exp' then
- b3 := exp(b2);
- if realfctoperator = 'ln' then
- begin
- if (b2 < 0) then
- begin
- error := 'taking the logarithm of negative number';
- goto 999;
- end;
- b3 := ln(b2);
- end;
-
- if realfctoperator = '''' then
- begin
- if (b2 = 0) then
- begin
- error := 'infinite value';
- goto 999;
- end;
- b3 := 1 / b2;
- end;
-
-
- end;
-
- if realfunctiontype = 'unary' then
- begin
- if realfctoperator = plus then
- b3 := +b1;
- if realfctoperator = minus then
- b3 := -b1;
- end;
-
-
- 999:
- end;
-
-
-
- end.